package com.li.yny.Dao;

import com.li.yny.bean.Students;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;

import javax.print.DocFlavor;
import java.util.List;

public class StudentImpl implements StudentDao {
    @Autowired
    JdbcTemplate jdbcTemplate;

    @Override
    public int insert() {
        String sql = "insert into students(number,name,grade,clbum,gender) values(?,?,?,?,?)";
        int update = jdbcTemplate.update(sql, new Object[]{"20030831", "张三", "2023", "Java", "男"});
        return update;
    }

    @Override
    public List<Students> selectAll() {
        String sql = "select * from students";
        List<Students> students = jdbcTemplate.query(sql, new BeanPropertyRowMapper<Students>(Students.class));
        return students;

    }

    @Override
    public Students getStudents(String number) {
        String sql = "select * from students where number=?";
        return null;
    }

    @Override
    public int update(Students students) {
        String sql = "update students set name=?,grade=?,clbum=?,gender=? where number=?";
        int update = jdbcTemplate.update(sql, students.getName(), students.getGrade(),
                students.getClbum(), students.getGender(), students.getNumber());
        return update;
    }
}